<% request.setAttribute("_vacio", new Object[0]);%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" 
%><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" 
%><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" 
%><%@ page contentType="text/html;charset=ISO-8859-1"
%><html:html locale="true">
    <head>
        <title><bean:message key="V_ConfirmarOferta.title"/></title>
        <html:base/>
        <script type="text/javascript" src="../js/prototype.js"></script>
        <script type="text/javascript" src="../js/ajax.js"></script>
        <script type="text/javascript">
            var idOferta = ${idOferta};
            var horast = ${empty D_Asignatura.horast ? "" : D_Asignatura.horast };
            var horasp = ${empty D_Asignatura.horasp ? "" : D_Asignatura.horasp };
            var horasl = ${empty D_Asignatura.horasl ? "" : D_Asignatura.horasl };
            var numcajitast =  Math.round(${D_Asignatura.horast/2});
            var horarioTeoria;
            var i;
            var bloquest = new Array();
            var bloquesp = new Array();
            var bloquesl = new Array();
            
            function horarios(){
                var horas = Array(""+<logic:iterate id="horario" collection="${empty L_Horario ? _vacio : L_Horario}">,Array(${horario.idHorario},${horario.dia},${horario.hora},'${horario.tipoHora}')</logic:iterate>);
                for(i=1;i<horas.length;i++){
                    if(horas[i][3] == 't')
                        bloquest.push(horas[i]);
                    else if(horas[i][3] == 'p')
                        bloquesp.push(horas[i]);
                    else if(horas[i][3] == 'l')
                        bloquesl.push(horas[i]);
                }
                prepararFormularioHorarioT("FTeoria","t",bloquest,bloquest.length,horast);
                prepararFormularioHorarioPL("FPractica","p",bloquesp,bloquesp.length,horasp);
                prepararFormularioHorarioPL("FLaboratorio","l",bloquesl,bloquesl.length,horasl);
                    

            <logic:iterate id="horario" collection="${empty L_Horario ? _vacio : L_Horario}">
                    $('dia${horario.idHorario}').selectedIndex = ${horario.dia-1};
            </logic:iterate>
            }
            
            function prepararFormularioHorarioT(form,tipo,bloque,len,horas){
                var k;
                for(i=1;i<=numcajitast;i++)
                        $(form+i).idHorario.value = 0;
                if(len){                    
                    k=0;
                    //for(j=1;j<numcajitast;j++){
                    j=1;
                    $(form+j).idHorario.value = bloque[k][0];
                    $(form+j).dia.selectedIndex = bloque[k][1]-1;
                    $(form+j).horai.value = bloque[k][2];
                    $(form+j).horaf.value = bloque[k+1][2];
                    try{
                        j=2;
                        k = 2;
                        $(form+j).idHorario.value = bloque[k][0];
                        $(form+j).dia.selectedIndex = bloque[k][1]-1;
                        $(form+j).horai.value = bloque[k][2];
                        $(form+j).horaf.value = bloque[k+1][2];
                    }catch(e){}
                }
                for(i=1;i<=numcajitast;i++){
                    $(form+i).tipoHora.value = tipo;
                    $("tr"+form+i).show();
                }
            }
            
            function prepararFormularioHorarioPL(form,tipo,bloque,len,horas){
                if(len){
                    $(form).idHorario.value = bloque[0][0];
                    $(form).dia.selectedIndex = bloque[0][1]-1;
                    $(form).horai.value = bloque[0][2];
                    $(form).horaf.value = bloque[len-1][2];
                }else{
                    $(form).idHorario.value = 0;
                }
                $(form).tipoHora.value = tipo;
                if(horas)
                    $("div"+form).show();
            }
            
            function colocarHoraFinalTeoria(hi){
                $('FTeoria1').horatf.value = (eval(hi)) ? (eval(hi) + 1) : "";   
            }
            
            function colocarHoraFinalTeoria2(hi){
                if(numcajitast > 1)
                    $('FTeoria2').horatf.value = (eval(hi)) ? (eval(hi) + 1) : "";
                else
                    $('FTeoria2').horatf.value = (eval(hi)) ? (eval(hi) + (horast - ((numcajitast - 1) * 2) - 1)) : "";
            }
        
            function colocarHoraFinalTeoria3(hi){
                    $('FTeoria3').horatf.value = (eval(hi)) ? (eval(hi) + (horast - ((numcajitast - 1) * 2) - 1)) : "";
            }
            
            function colocarHoraFinalPractica(hi){
                $('horapf').value = (eval(hi)) ? (eval(hi) + (horasp - 1)) : "";
            }
            
            function colocarHoraFinalLaboratorio(hi){
                $('horalf').value = (eval(hi)) ? (eval(hi) + (horasl - 1)) : "";
            }
            
            function registrarPersistenteTeoria(form,action,mensaje,bloque){
                var c;
                for(c=1;c<=numcajitast;c++){
                    registrarPersistente($(form+c),action,mensaje,bloque);
                }
                return false;
            }
    
            function registrarPersistente(form,action,mensaje,bloque){
                var variables;
                var j=0;
                try{
                    if($(form).idHorario.value > 0){
                        for(i=$(form).horai.value;i<=$(form).horaf.value;i++){
                            variables = "idHorario="+bloque[j][0]+"&dia="+$(form).dia.value+"&hora="+i+"&tipoHora="+$(form).tipoHora.value+"&oferta="+idOferta;
                            j++;
                            registrar(variables,action,mensaje);
                        }
                    }else{
                        var inicio = $(form).horai.value;
                        var fin = $(form).horaf.value;
                        for(i=inicio;i<=fin;i++){
                            variables = "idHorario=0&dia="+$(form).dia.value+"&hora="+i+"&tipoHora="+$(form).tipoHora.value+"&oferta="+idOferta;
                            registrar(variables,"/colisiones/HorarioCrear.do",mensaje);
                        }
                        alert("Horario Creado");
                        setTimeout("recargar('/colisiones/OfertaI.do?idOferta='+idOferta)",5000);
                    }
                }catch(e){
                    alert(e);
                }
                return false;
            }
            

        </script>
        <link rel="stylesheet" type="text/css" href="../css/style.css"></link>
<style type="text/css">
div#box30678 {width: 400px; margin: 40px auto; }
form#30678 {float: left; margin: 0; padding: 0; display: inline; width: 400px; }
form#30678 p {float: left; margin: 0; padding: 0; display: inline; }
form#30678 label {float: left; margin: 0; padding: 0; display: inline; overflow: hidden; }
form#30678 input {float: left; margin: 0; padding: 0; display: inline; }
  form#30678 p#30685_C {clear: both; width: 400px; }
  form#30678 p#30685_C label {clear: both; width: 400px; }
  form#30678 p#30685_C input {clear: both; width: 396px; }
  form#30678 p#30683_C {clear: both; width: 400px; }
  form#30678 p#30683_C label {clear: both; width: 400px; }
  form#30678 p#30683_C input {clear: both; width: 396px; }
  form#30678 p#30684_C {clear: both; width: 400px; }
  form#30678 p#30684_C label {clear: both; width: 400px; }
  form#30678 p#30684_C input {clear: both; width: 396px; }
  form#30678 p#30681_C {clear: both; width: 400px; }
  form#30678 p#30681_C label {clear: both; width: 400px; }
  form#30678 p#30681_C input {clear: both; width: 396px; }
  form#30678 p#30679_C {clear: both; width: 400px; }
  form#30678 p#30679_C label {clear: both; width: 400px; }
  form#30678 p#30679_C input {clear: both; width: 396px; }
  form#30678 p#30680_C {clear: both; width: 400px; }
  form#30678 p#30680_C label {clear: both; width: 400px; }
  form#30678 p#30680_C input {clear: both; width: 396px; }
  form#30678 p#30682_C {clear: both; width: 400px; }
  form#30678 p#30682_C label {clear: both; width: 400px; }
  form#30678 p#30682_C input {clear: both; width: 396px; }

</style>
    </head>
    <body onload="horarios()">
        <div id="header">
            <div id="title"><bean:message key="oferta.title"/></div>
            <div id="menu">
                <ul id="nav">
               
                </ul>
            </div>
        </div>
        <div id="body_wrapper">
            <div id="body">
                <div id="split">
                    <div class="top"></div>
                    <div id="left">
                        <div class="content">
                            ${empty msg ? "" : msg}
                <div class="box30678">
                <%--
                    <html:form styleId="F30678" action="/OfertaAct.do">
                    <html:hidden property="idOferta"/><table>
                      <tr><td id="30683_C"><label for="30683"><bean:message key="FOferta.label1"/></label></td><td>&nbsp;<html:select styleId="30683" property="periodo"><html:optionsCollection property="listPeriodo"/></html:select></td></tr>
                      <tr><td id="30681_C"><label for="30681"><bean:message key="FOferta.label3"/></label></td><td>&nbsp;<html:select styleId="30681" property="planDeEstudios" ><html:optionsCollection property="listPlanDeEstudios"/></html:select></td></tr>
                      <tr><td id="30680_C"><label for="30680"><bean:message key="FOferta.label5"/></label></td><td>&nbsp;<html:select styleId="30680" property="requisito"><html:optionsCollection property="listRequisitos"/></html:select></td></tr>
                  </table>
                  <html:submit styleClass="button"><bean:message key="oferta.label0"/></html:submit>
                </html:form>
                --%>
                
                <html:form styleId="F30678" action="A_ConfirmarOferta.do">
                    <html:hidden property="idOfertaEnviada"/>
                    <table>
                      <tr><td id="30683_C">
                            <label for="30683"><bean:message key="FConfOferta.label0"/></label>
                          </td>
                          <td>&nbsp;<select id="aprobado" name="aprobado">
                                            <option value="0">No</option>
                                            <option value="1">Si</option>
                                   </select>
                          </td></tr>
                      <tr><td id="30681_C">
                            <label for="30681"><bean:message key="FConfOferta.label1"/></label>
                          </td>
                          <td>&nbsp;<html:textarea styleId="30681" property="comentario"/></td></tr>
                   </table>
                  <html:submit styleClass="button"><bean:message key="oferta.label0"/></html:submit>
               </html:form>
               </div>
                <h2>Horario Teor&iacute;a (${D_Asignatura.horast} horas)</h2>
                 <table border="1">
                    <tbody>
                        <tr id="trFTeoria1" style="display:none">
                            <td>
                                <html:form styleId="FTeoria1" action="/HorarioAct.do" onsubmit="return registrarPersistenteTeoria('FTeoria',this.action,'Horario ',bloquest);">
                                    <input type="hidden" name="idHorario">
                                       <input type="hidden" name="tipoHora">
                                <table border="0">
                                    <tr>
                                        <td>D&iacute;a</td>
                                        <td>Hora Inicio</td>
                                        <td>Hora final</td>                                        
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="dia" name="dia">
                                            <option value="1">Lunes</option>
                                            <option value="2">Martes</option>
                                            <option value="3">Mi&eacute;rcoles</option>
                                            <option value="4">Jueves</option>
                                            <option value="5">Viernes</option>
                                            <option value="6">S&aacute;bado</option>
                                          </select>
                                        </td>
                                        <td align="center"><input type="text" name="horai" id="horati" size="1" onkeyup="colocarHoraFinalTeoria(this.value);"></td>
                                        <td align="center"><input type="text" name="horaf" id="horatf" size="1"></td>
                                    </tr>
                                    <tr><td>&nbsp;</td></tr>
                                    
                                </table>
                                </html:form>
                            </td>
                        </tr>
                        <tr id="trFTeoria2" style="display:none">
                            <td>
                                <html:form styleId="FTeoria2" action="/HorarioAct.do" onsubmit="return registrarPersistenteTeoria('FTeoria',this.action,'Horario ',bloquest);">
                                    <input type="hidden" name="idHorario">
                                       <input type="hidden" name="tipoHora">
                                <table border="0">
                                    <tr>
                                        <td>D&iacute;a</td>
                                        <td>Hora Inicio</td>
                                        <td>Hora final</td>                                        
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="dia" name="dia">
                                            <option value="1">Lunes</option>
                                            <option value="2">Martes</option>
                                            <option value="3">Mi&eacute;rcoles</option>
                                            <option value="4">Jueves</option>
                                            <option value="5">Viernes</option>
                                            <option value="6">S&aacute;bado</option>
                                          </select>
                                        </td>
                                        <td align="center"><input type="text" name="horai" id="horati" size="1" onkeyup="colocarHoraFinalTeoria2(this.value);"></td>
                                        <td align="center"><input type="text" name="horaf" id="horatf" size="1"></td>
                                    </tr>
                                    <tr><td>&nbsp;</td></tr>
                                    <tr>
                                        <td colspan="3" align="center"><html:submit value="Aceptar" styleId="submit"></html:submit></td>
                                    </tr>
                                </table>
                                </html:form>
                            </td>
                        </tr>
                        <tr id="trFTeoria3" style="display:none">
                            <td>
                                <html:form styleId="FTeoria3" action="/HorarioAct.do" onsubmit="return registrarPersistenteTeoria('FTeoria',this.action,'Horario ',bloquest);">
                                    <input type="hidden" name="idHorario">
                                       <input type="hidden" name="tipoHora">
                                <table border="0">
                                    <tr>
                                        <td>D&iacute;a</td>
                                        <td>Hora Inicio</td>
                                        <td>Hora final</td>                                        
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="dia" name="dia">
                                            <option value="1">Lunes</option>
                                            <option value="2">Martes</option>
                                            <option value="3">Mi&eacute;rcoles</option>
                                            <option value="4">Jueves</option>
                                            <option value="5">Viernes</option>
                                            <option value="6">S&aacute;bado</option>
                                          </select>
                                        </td>
                                        <td align="center"><input type="text" name="horai" id="horati" size="1" onkeyup="colocarHoraFinalTeoria3(this.value);"></td>
                                        <td align="center"><input type="text" name="horaf" id="horatf" size="1"></td>
                                    </tr>
                                    <tr><td>&nbsp;</td></tr>
                                    <tr>
                                        <td colspan="3" align="center"><html:submit value="Actualizar" styleId="submit"></html:submit></td>
                                    </tr>
                                </table>
                                </html:form>
                            </td>
                        </tr>
                    </table>
                
                    <br>

            <div id="divFPractica" style="display:none">
                <h2>Horario Pr&aacute;ctica (${D_Asignatura.horasp} horas)</h2>
                 <table border="1">
                    <tbody>
                        <tr>
                            <td>
                                <html:form styleId="FPractica" action="/HorarioAct.do" onsubmit="return registrarPersistente(this,this.action,'Horario ',bloquesp);">
                                    <input type="hidden" name="idHorario">
                                        <input type="hidden" name="tipoHora">
                                <table border="0" width="300">
                                    <tr>
                                        <td>D&iacute;a</td>
                                        <td>Hora Inicio</td>
                                        <td>Hora Final</td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="dia" name="dia">
                                            <option value="1">Lunes</option>
                                            <option value="2">Martes</option>
                                            <option value="3">Mi&eacute;rcoles</option>
                                            <option value="4">Jueves</option>
                                            <option value="5">Viernes</option>
                                            <option value="6">S&aacute;bado</option>
                                          </select>
                                        </td>
                                        <td align="center"><input type="text" name="horai" id="horapi" size="1" onkeyup="colocarHoraFinalPractica(this.value);"></td>
                                        <td align="center"><input type="text" name="horaf" id="horapf" size="1"></td>
                                    </tr>
                                    <tr><td>&nbsp;</td></tr>
                                    <tr>
                                        <td colspan="3" align="center"><html:submit value="Actualizar" styleId="submit"></html:submit></td>
                                    </tr>
                                </table>
                                </html:form>
                            </td>
                        </tr>
                    </table>
                    </div>
                <br>
                
                
                <div id="divFLaboratorio" style="display:none">
                <h2>Horario Laboratorio (${D_Asignatura.horasl} horas)</h2>
                 <table border="1">
                    <tbody>
                        <tr>
                            <td>
                                <html:form styleId="FLaboratorio" action="/HorarioAct.do" onsubmit="return registrarPersistente(this,this.action,'Horario ',bloquesl);">
                                  <input type="hidden" name="idHorario">
                                       <input type="hidden" name="tipoHora">
                                <table border="0">
                                    <tr>
                                        <td>D&iacute;a</td>
                                        <td>Hora Inicio</td>
                                        <td>Hora final</td>
                                        
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="dia" name="dia">
                                            <option value="1">Lunes</option>
                                            <option value="2">Martes</option>
                                            <option value="3">Mi&eacute;rcoles</option>
                                            <option value="4">Jueves</option>
                                            <option value="5">Viernes</option>
                                            <option value="6">S&aacute;bado</option>
                                          </select>
                                        </td>
                                        <td align="center"><input type="text" name="horai" id="horali" size="1" onkeyup="colocarHoraFinalLaboratorio(this.value);"></td>
                                        <td align="center"><input type="text" name="horaf" id="horalf" size="1"></td>
                                    </tr>
                                    <tr>
                                        <td colspan="3"><html:submit value="Actualizar" styleId="submit"></html:submit></td>
                                    </tr>
                                </table></html:form>
                            </td>
                        </tr>
                    </table>
                </div>
                
                
                
                
                
                <br>
                <table border="1">
                    <tbody>
                        <logic:iterate id="horario" collection="${empty L_Horario ? _vacio : L_Horario}">
                            <tr>
                                <td>
                                    <html:form styleId="F31168" action="/HorarioAct.do" onsubmit="return RegistroCrear(this,this.action,'Horario ');">
                                        <html:hidden name="idHorario" value="${horario.idHorario}" property="idHorario"/>
                                <table border="0">
                                    <tr>
                                        <td>
                                            ${horario.dia == 1? "Lunes:":""}
                                            ${horario.dia == 2? "Martes:":""}
                                            ${horario.dia == 3? "Mi&eacute;rcoles:":""}
                                            ${horario.dia == 4? "Jueves:":""}
                                            ${horario.dia == 5? "Viernes:":""}
                                            ${horario.dia == 6? "S&aacute;bado:":""}

                                        </td>
                                        <td>${horario.hora}</td>
                                        <td>${horario.tipoHora == "t"? "[Teor&iacute;a]":""}
                                            ${horario.tipoHora == "l"? "[Laboratorio]":""}
                                            ${horario.tipoHora == "p"? "[Pr&aacute;tica]":""}
                                        </td>
                                   </tr>
                                </table></html:form>
                                </td>
                                
                            </tr>
                        </logic:iterate>
                    </tbody>
                </table>
                        </div>
                    </div>
                    <div id="right"><jsp:include page="/ppal/menu.jsp" flush="true"/></div>
                    <div class="clearer"></div>
                    <div class="bottom"></div>
                </div>
                <div class="clearer"></div>
            </div>
            <div class="clearer"></div>
        </div>
        <div id="end_body"></div>
        <h3 class="title"></h3>
        <div id="footer"> <bean:message key="bottom.label"/> </div>
        
    </body>
</html:html>